<?php
/**
 * Created by PhpStorm.
 * User: mars
 * Date: 2019/2/7
 * Time: 2:34 PM
 */

namespace api\controllers;

use api\models\Comment;
use Yii;


class CommentController extends BaseController
{
    public $modelClass = "\api\models\Comment";

    public function actions()
    {
        $actions = parent::actions();
        unset($actions['create']);

        return $actions;
    }

    public function actionCreate()
    {
        $commentModel = new Comment();
        if ($commentModel->load(Yii::$app->getRequest()->getBodyParams(), '') && $commentModel->save(false)) {
//            var_dump($commentModel);
            if (Yii::$app->feehi->website_comment_need_verify) {
                $tips = Yii::t('frontend', 'Comment waiting for approved.');

                return $tips;
            }

//            $commentModel->uid = Yii::$app->getUser()->id;

            return $commentModel;
        } else {
            $temp = $commentModel->getErrors();
            $str  = '';
            foreach ($temp as $v) {
                $str .= $v[0] . "<br>";
            }
            Yii::$app->response->statusCode = 400;

            return ["error" => $commentModel];
        }
    }

    public function actionViewComment($article_id)
    {
        $commentModel = new Comment();
        $commentList  = $commentModel->getCommentByAid($article_id);

        return $commentList;
    }
}